define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/no_pay/index',
                    add_url: 'order/no_pay/add',
                    edit_url: 'order/no_pay/edit',
                    del_url: 'order/no_pay/del',
                    multi_url: 'order/no_pay/multi',
                    table: 'shop_order',
                    ajax_url:{
                        btn_5:{data:{'method':"3"},url:"order/order/update_status",fc:function(data){
                                return true;
                            }}//催付
                    }

                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'order_id',
                sortName: 'order_id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'username', title: __('Paike_name')},
                        {field: 'mobile', title: __('Paike_mobile')},
                        {field: 'order_sno', title: __('Order_sno')},
                        {field: 'k.task_sno', title: __('Task_sno')},
                        {field: 'tao_bao_order_no', title: __('Tao_bao_order_no')},
                        {field: 'o.real_money', title: __('Cash'),operate:'BETWEEN'},
                        {field: 'create_time', title: __('create_time'), operate:'BETWEEN', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'user_payed', title: __('Status'),searchList: {"1":__('未付款'),"2":__('已付款')},formatter: Table.api.formatter.normal,operate:false},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            formatter:function(value,row,index) {

                                var table = this.table;
                                // 操作配置
                                var options = table ? table.bootstrapTable('getOptions') : {};
                                // 默认按钮组
                                var buttons = $.extend([], this.buttons || []);
                                // if (options.extend.del_url !== '') {
                                //     buttons.push(
                                //         {
                                //             name: 'del',
                                //             icon: 'fa fa-trash',
                                //             title: __('Del'),
                                //             extend: 'data-toggle="tooltip"',
                                //             classname: 'btn btn-xs btn-danger btn-delone'
                                //         }
                                //     );
                                // }
                                console.log(row);
                                if(row["o.status"]==5){
                                    buttons.push(  {
                                        name: 'btn_5',
                                        text: "催付",
                                        extend: 'data-toggle="tooltip" data-name="btn_5" data-title="催付" ',
                                        classname: 'btn btn-xs btn-success btn-magic btn-ajax',
                                    });
                                }


                                return Table.api.buttonlink(this, buttons, value, row, index, 'operate');
                            }
                        }
                    ]
                ]
            });



            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            $(function(){
                //console.log($(".example2"))
                require(['img_css/easy-loading','img_css/hammer.min','img_css/jquery.mousewheel.min','img_css/zoom-marker'],function(){
                    // $('#zoom-marker-img').zoomMarker({
                    //     src: $('#zoom-marker-img').data("url"),
                    //     rate: 0.2,
                    //     width: 100,
                    //     max: 1000,
                    //     markers:[
                    //         //{src:"img/marker.svg", x:500, y:500}
                    //     ]
                    // });
                    $("img").each(function(){
                        console.log($(this).data("url"));
                        if($(this).data("url")!=undefined && $(this).data("url")!="") {
                            $(this).zoomMarker({
                                src: $(this).data("url"),
                                rate: 0.1,
                                min: 100,
                                width: 100,
                                max: 3000,
                                markers: [
                                    //{src:"img/marker.svg", x:500, y:500}
                                ],
                            });
                        }
                    });
                    // $('#zoom-marker-img-alt').zoomMarker({
                    //     src: $('#zoom-marker-img-alt').data("url"),
                    //     rate: 0.1,
                    //     min:100,
                    //     width: 100,
                    //     max: 3000,
                    //     markers:[
                    //         //{src:"img/marker.svg", x:500, y:500}
                    //     ]
                    //
                    //
                    // });
                })
            });
            Controller.api.bindevent();

        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});